<template>
  <div class="xd-LearningHome-OnlineExams-StartExam p_10">
    <el-card class="box-card" shadow="hover">
      <div slot="header" class="title">考试</div>
      <PaperExamDetailInfo :paperExamDetail="paperExamDetail" :examType="examType"></PaperExamDetailInfo>
    </el-card>
  </div>
</template>
<script>
const PaperExamDetailInfo = () => import('@/components/PaperExamDetailInfo')

export default {
  name: 'StartExam',
  components: {
    PaperExamDetailInfo
  },
  data() {
    return {
      paperExamDetail: {
        paperId: '',
        title: '',
        paperQuestionNum: 0,
        countdown: 0,
        credits: 0,
        score: 0,
        useTime: 0,
        examScore: 0,
        questions: []
      },
      examType: 0
    }
  },
  created() {
    this.examType = parseInt(this.$route.query.examType)
    var tempInfo = utils.getItem('ExamInstructionsPaperInfo')
    if (tempInfo) {
      this.paperExamDetail.paperId = tempInfo.paperId
      this.paperExamDetail.title = tempInfo.paperTitle
      this.paperExamDetail.paperQuestionNum = tempInfo.paperQuestionNum
      this.paperExamDetail.paperTimeLong = tempInfo.paperTimeLong * 60
    } else {
      this.etchDetail(this.$route.query.tid)
    }
    this.getStartExam()
    // 正式环境开启
    utils.stopRefresh()
  },
  methods: {
    getStartExam() {
      const path = this.examType === 1 ? '/examination/StartExam' : '/curriculum/StartTest'
      utils.post(path, { paperId: this.paperExamDetail.paperId }, res => {
        if (res.success) {
          for (var i = 0; i < res.data.rows.length; i++) {
            //  questionType 试题类型 2 填空题 3 判断题  0 单选 1 多选
            switch (res.data.rows[i].questionType) {
              case 2:

                break;
              case 0:
              case 3:
                res.data.rows[i].selectedAnswer = ''
                break;
              case 1:
                res.data.rows[i].selectedAnswer = []
                break;
            }
          }
          this.paperExamDetail.questions = res.data.rows
        }
      })
    },
    fetchDetail(tid) {
      utils.post('examination/ExamInstructions', {
        paperId: tid
      }, res => {
        if (res.success) {
          this.paperExamDetail.paperId = res.data.paperId
          this.paperExamDetail.title = res.data.paperTitle
          this.paperExamDetail.paperQuestionNum = res.data.paperQuestionNum
          this.paperExamDetail.paperTimeLong = res.data.paperTimeLong * 60
        }
      })
    }
  }
}
</script>
<style lang="less">
.xd-LearningHome-OnlineExams-StartExam {
  .el-card__body {
    padding: 0px;
  }
}
</style>